package csm.web.core;

import javax.servlet.http.HttpServletRequest;

import csm.common.StringUtil;

public class RequestHelper {
	private HttpServletRequest req;

	@SuppressWarnings("unused")
	private RequestHelper(){

	}
	public RequestHelper( HttpServletRequest request ){
		req = request;
	}

	public String getParameter(String key){
		return this.req.getParameter(key);
	}

	public String getParameter(String key, String defaultValue){
		String rtn = this.req.getParameter(key);
		if(StringUtil.isNullOrEmpty(rtn))
			return defaultValue;
		return rtn;
	}

	public int getIntParameter(String key) {
		String rtn = this.req.getParameter(key);
		if (StringUtil.isNullOrEmpty(rtn))
			return 0;
		try {
			return Integer.parseInt(rtn);
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	public int getIntParameter(String key, int defaultValue) {
		String rtn = this.req.getParameter(key);
		if (StringUtil.isNullOrEmpty(rtn))
			return defaultValue;
		try {
			return Integer.parseInt(rtn);
		} catch (NumberFormatException e) {
			return defaultValue;
		}
	}
}
